/*
 *  $Id: Inquisitor.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Light.Creatures {
    public class Inquisitor: CreatureCard {
        public Inquisitor(): base("001_l_c_inquisitor") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Light;
            Value = 100;
            Damage = 4;
            Health = 6;
            AddManaCost(ElementType.Light, 4);
        }
        public override void SetNaturalAffects(ICollector<Affect> affects) {
            affects.Add<Affects.Tireless>();
            affects.Add<InquisitorAffect>();
        }

        private class InquisitorAffect: Affect {
            private bool _hit;

            public InquisitorAffect() {
                _hit = false;
            }

            public override string Id {
                get { return AffectManager.GetCardId<Inquisitor>(null); }
            }

            public override void SetAffect() {
                base.SetAffect();
                LocalSummary.OnOffenceReady += DoReady;
                LocalSummary.OnDefenceReady += DoReady;
                LocalSummary.OnHit += DoHit;
                LocalSummary.OnAfterDamage += Damage;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                LocalSummary.OnOffenceReady -= DoReady;
                LocalSummary.OnDefenceReady -= DoReady;
                LocalSummary.OnHit -= DoHit;
                LocalSummary.OnAfterDamage -= Damage;
            }

            private void DoReady(Creature cr) {
                _hit = false;
            }
            private void DoHit(Creature hitter, AbstractObject target, int damage) {
                _hit = true;
            }
            private void Damage(AbstractObject target, DamageInfo damage) {
                Creature attacker;
                if (_hit || !MeleeDamageInfo.TryGetAttacker(damage, out attacker)) return;
                Creature inquisitor = target as Creature;
                if (inquisitor == null || !inquisitor.IsDeath) return;
                int dice = Game.Current.GetDiceNextValue();
                if (dice >= 3)
                    attacker.DamageDirectBy(inquisitor.NewDamage(), true);
            }
        }
    }
}
